<!-- saved from url=(0014)about:internet -->
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title>PriorityToIntConverter.as</title>
<link rel="stylesheet" type="text/css" href="../../../../SourceStyles.css"/>
</head>

<body><pre><span class="ActionScriptpackage">package</span> <span class="ActionScriptDefault_Text">task</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">domain</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">converters</span>
<span class="ActionScriptBracket/Brace">{</span>
    <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">mx</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">collections</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">ArrayList</span>;

    <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">org</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">flexthinker</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">binding</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">conversion</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">Converter</span>;

    <span class="ActionScriptReserved">import</span> <span class="ActionScriptDefault_Text">task</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">domain</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">TaskPriority</span>;

    <span class="ActionScriptReserved">public</span> <span class="ActionScriptclass">class</span> <span class="ActionScriptDefault_Text">PriorityToIntConverter</span> <span class="ActionScriptReserved">implements</span> <span class="ActionScriptDefault_Text">Converter</span>
    <span class="ActionScriptBracket/Brace">{</span>
        <span class="ActionScriptReserved">private</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">priorities</span>:<span class="ActionScriptDefault_Text">ArrayList</span>;

        <span class="ActionScriptASDoc">/**
         *
         * @param prioritiesMetadata
         *          The list with priorities coming from TaskMetadata.
         *          List is used to convert an int into a TaskPriority
         */</span>
        <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">PriorityToIntConverter</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">prioritiesMetadata</span>:<span class="ActionScriptDefault_Text">ArrayList</span><span class="ActionScriptBracket/Brace">)</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">this</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">priorities</span> <span class="ActionScriptOperator">=</span> <span class="ActionScriptDefault_Text">prioritiesMetadata</span>;
        <span class="ActionScriptBracket/Brace">}</span>


        <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">convertForward</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span>:<span class="ActionScriptOperator">*</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptOperator">*</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">value</span> <span class="ActionScriptOperator">?</span> 5 <span class="ActionScriptOperator">-</span> <span class="ActionScriptDefault_Text">TaskPriority</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptBracket/Brace">)</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">priority</span> : 1 ;
        <span class="ActionScriptBracket/Brace">}</span>


        <span class="ActionScriptReserved">public</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">convertReverse</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span>:<span class="ActionScriptOperator">*</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptOperator">*</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">findTaskByPriority</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">value</span><span class="ActionScriptBracket/Brace">)</span>;
        <span class="ActionScriptBracket/Brace">}</span>

        <span class="ActionScriptReserved">private</span> <span class="ActionScriptfunction">function</span> <span class="ActionScriptDefault_Text">findTaskByPriority</span><span class="ActionScriptBracket/Brace">(</span><span class="ActionScriptDefault_Text">priority</span>:<span class="ActionScriptDefault_Text">int</span><span class="ActionScriptBracket/Brace">)</span>:<span class="ActionScriptDefault_Text">TaskPriority</span>
        <span class="ActionScriptBracket/Brace">{</span>
            <span class="ActionScriptReserved">for each</span> <span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptvar">var</span> <span class="ActionScriptDefault_Text">task</span>:<span class="ActionScriptDefault_Text">TaskPriority</span> <span class="ActionScriptReserved">in</span> <span class="ActionScriptDefault_Text">priorities</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">source</span> <span class="ActionScriptBracket/Brace">)</span>
            <span class="ActionScriptBracket/Brace">{</span>
                <span class="ActionScriptReserved">if</span> <span class="ActionScriptBracket/Brace">(</span> <span class="ActionScriptDefault_Text">task</span><span class="ActionScriptOperator">.</span><span class="ActionScriptDefault_Text">priority</span> <span class="ActionScriptOperator">==</span> 5 <span class="ActionScriptOperator">-</span> <span class="ActionScriptDefault_Text">priority</span> <span class="ActionScriptBracket/Brace">)</span>
                <span class="ActionScriptBracket/Brace">{</span>
                    <span class="ActionScriptReserved">return</span> <span class="ActionScriptDefault_Text">task</span>;
                <span class="ActionScriptBracket/Brace">}</span>
            <span class="ActionScriptBracket/Brace">}</span>

            <span class="ActionScriptReserved">return</span> <span class="ActionScriptReserved">null</span>;
        <span class="ActionScriptBracket/Brace">}</span>
    <span class="ActionScriptBracket/Brace">}</span>
<span class="ActionScriptBracket/Brace">}</span>
</pre></body>
</html>
